package sim.tests.games.bullet;

import java.util.Random;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.utils.Array;

import sim.Image;
import sim.misc.Holder;
import sim.states.BasicGame;

public class Core extends BasicGame
{
	Array<Tile> tiles;
	Image image;
	Grass grass;
	BitmapFont font;
	boolean creatingWorld;
	Random rad = new Random();
	final int MAX_CHANCE = 140;
	int chance = MAX_CHANCE;

	@Override
	public void init()
	{
		setWorldSize(200, 150);
		font = new BitmapFont();
		font.setScale(0.25f);
		
		
		grass = new Grass(0, 0);
		tiles = new Array<Tile>();

		creatingWorld = true;
		int size = 10;
		
		float length = 200;
		
		for (float x = 0; x < length; x++)
		{
			System.out.println((x / length) * 100 + "%");
			
			for(int y = 0; y < length; y++)
			{
				
			tiles.add(new Grass(x, y));
			
			
			
			if(rad.nextInt(chance) == 0)
			{
				//tiles.add(new Tile(x, y, new Image("grassTall.png")));
				for(int yy = y - rad.nextInt(size); yy < y + rad.nextInt(size); yy++)
					for(int xx = (int) (x - rad.nextInt(size)); xx < x + rad.nextInt(size); xx++)
					{
						if(rad.nextInt(4) == 0)
						tiles.add(new Tile(xx, yy, new Image("tree.png")));
					}
				
				
					for(int xx = (int) (x - rad.nextInt(size)); xx < x + rad.nextInt(size); xx++)
					{
						for(int yy = y - rad.nextInt(size); yy < y + rad.nextInt(size); yy++)
						if(rad.nextInt(4) == 0)
						tiles.add(new Tile(xx, yy, new Image("tree.png")));
					}

				
			}
			}
			
			
			

		}
		creatingWorld = false;

	}

	@Override
	public void update(float delta)
	{
		float moveSpeed = 16f * delta;
		
		if(Gdx.input.isKeyPressed(Input.Keys.W))
			camera.translate(0f, moveSpeed, 0);
		
		if(Gdx.input.isKeyPressed(Input.Keys.S))
			camera.translate(0f, -moveSpeed, 0);
		
		if(Gdx.input.isKeyPressed(Input.Keys.D))
			camera.translate(moveSpeed, 0f, 0);
		
		if(Gdx.input.isKeyPressed(Input.Keys.A))
			camera.translate(-moveSpeed, 0f, 0); 
	}

	@Override
	public void draw()
	{
		
		for (Tile t : tiles)
			t.draw();

				font.draw(Holder.b, Integer.toString(Gdx.graphics.getFramesPerSecond()), 5, 5);
				
		//grass.draw();
	}

}
